<template>
	<view>
		<view class="video-cont" v-if="videoInfo">
			<view class="video-box-img" v-if="userAccredit" @click="visible = true">
				<image class="video-paly-icon" src="../../../static/icon/paly.png" mode=""></image>
				<image class="video-box-img-bg" :src="videoInfo.img" mode="aspectFill"></image>
			</view>
			<!-- 视频 -->
			<video
				v-if="!userAccredit"
				class="video-box"
				id="myVideo"
				:src="videoInfo.url"
				:controls="true"
				:poster="videoInfo.img"
				objectFit="cover"
			></video>
		</view>
		<view class="cont" v-if="articleInfo">
			<view class="box">
				<!-- 文章内容 -->
				<view class="article-cont">
					<!-- 标题 -->
					<view class="article-title">{{articleInfo.title}}</view>
					<!-- 富文本？ -->
					<view class="article-detail">
						<jyf-parser :html="articleInfo.info"></jyf-parser>
					</view>
				</view>
				<!-- 推荐视频 -->
				<video-list v-if="articleInfo.list.length > 0" :list="articleInfo.list" @paly="onPaly" ></video-list>
			</view>
		</view>
		<!-- 登录弹窗 -->
		<v-register v-if="visible" @cancel="visible = false"></v-register>
	</view>
</template>

<script>
	import ActivityApi from "@/api/activity.js";
	import videoList from "../com/recommend-list.vue";
	import jyfParser from "@/components/jyf-parser/jyf-parser.vue";
	
	export default {
		components: {
			videoList,
			jyfParser
		},
		data() {
			return {
				visible: false,
				articleInfo: null,
				videoInfo: null
			};
		},
		// 计算属性
		computed: {
			userAccredit() {
				return this.$store.state.userAccredit;
			}
		},
		onLoad({id}) {
			this.getDateil(id)
		},
		methods: {
			async getDateil(id) {
				const res = await ActivityApi.getActivityDetail({id})
				console.log(res)
				this.articleInfo = res
				if(res.list.length > 0) {
					this.videoInfo = res.list[0];
				}
			},
			onPaly(e) {
				if(this.videoInfo.id == e.id) {
					return
				}
				this.videoInfo = e
			}
		}
	}
</script>

<style lang="scss" scoped>
	.video-cont {
		width: 100vw;
		height: 423rpx;
		position: relative;
		.video-box-img{
			width: 100vw;
			height: 423rpx;
			position: relative;
			font-size: 0;
			.video-paly-icon{
				position: absolute;
				width: 138rpx;
				height: 137rpx;
				top: 0;
				left: 0;
				bottom: 0;
				right: 0;
				margin: auto;
				z-index: 100;
			}
			.video-box-img-bg{
				width: 100%;
				height: 100%;
			}
		}
		.video-box {
			width: 100vw;
			height: 423rpx;
		}
	}
	.cont{
		padding: 26rpx;
		padding-bottom: calc(env(safe-area-inset-bottom) + 26rpx);
		.box{
			background-color: $color-white;
			border-radius: 10rpx;
			box-shadow: 2rpx 3rpx 6rpx rgba(#000, .1);
			.article-cont{
				padding: 26rpx;
				.article-title{
					font-size: 42rpx;
					line-height: 42rpx;
					margin-bottom: 24rpx;
					color: $text-color;
				}
				.article-detail{
					padding: 24rpx 0;
					font-size: 22rpx;
					color: $text-color-grey;
					line-height: 28rpx;
					border: {
						top: 1px solid;
						bottom: 1px solid;
						color: #eee;
					}
				}
			}
		}
	}
</style>
